<!--<!DOCTYPE html>-->
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <title>探亲外卖管理后台</title>
    <link rel="shortcut icon" href="/static/visites/images/icon.png">
    <!--css-->
    <link href="/static/visites/css/bootstrap.min.css" rel="stylesheet" type="text/css">
    <link href="/static/visites/css/icons.css" rel="stylesheet" type="text/css">
    <link href="/static/visites/css/style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div class="wrapper-page">
    <p hidden="hidden" >{% csrf_token %}</p>
    <div class="card">
        <div class="card-body">
            <h3 class="text-center mt-0 m-b-15">
                <a href="index.html" class="logo logo-admin"><img src="/static/visites/images/icon.png" alt="logo"></a>
            </h3>
            <div class="p-3">
                <form class="form-horizontal m-t-20" action="index.html" onsubmit="return check()">
                    <div class="error-mess" >
                        <span class="loginError" style="color: red" ></span>
                    </div>
                    <div class="form-group row">
                        <div class="col-12">
                            <input class="form-control" value="{{username}}" id="username" type="text" required="max_length=5" placeholder="用户名">
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-12">
                            <input class="form-control" value="{{ password }}" id ="password" type="password" required="max_length=6" placeholder="密码">
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-12">
                            <div class="custom-control custom-checkbox">
                                <input type="checkbox" value="{{ customCheck }}" class="custom-control-input" id="customCheck">
                                <label class="custom-control-label" for="customCheck">记住密码</label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group text-center row m-t-20">
                        <div class="col-12">
                            <button class="btn btn-info btn-block waves-effect waves-light" id="loginform" type="submit">登录</button>
                        </div>
                    </div>
                </form>
            </div>

        </div>
    </div>
</div>
<script src="/static/visites/js/jquery.min.js"></script>
<script src="/static/visites/js/bootstrap.min.js"></script>
<script src="/static/visites/js/jquery.slimscroll.js"></script>
<script src="/static/visites/js/jquery.cookie.js"></script>
<script>

    $(document).ready(function () {
        if ($('#customCheck').val() == 1){
            $('#customCheck').click()
        }

        //提交登录
        $("#loginform").click(function () {
            //获取用户名，密码，记住密码的值
              var username = $('#username').val();
              var password =  $('input[type="password"]').val();
              var customCheck = $('#customCheck').is(":checked")?1:0;
            $.ajaxSetup({
               data: {
                   csrfmiddlewaretoken: '{{ csrf_token }}' },
              });
              $.ajax({
                  type:"POST",
                  url: '/login/loginCheck',
                  data: {
                      username:username,
                      password:password,
                      customCheck:customCheck
                  },
                  dataType:'json',
                  cache:false,
                  success: function(data) {
                      if(data == 1 ){
                          location.href = '../../index/index';
                      }
                      if(data == -1 || data == 0 ){
                      $('.loginError').html('用户名或密码错误，请重新输入').show();
                      }
                      if(data == 2){
                      $('.loginError').html('请输入用户名或密码！').show();
                      }
                  },
                  error: function() {
                      $('.loginError').html('请求失败，请刷新页面后重试').show();
                  }
              });
                return false;
                });

    });

    $(function () {
        $.ajaxSetup({
            headers: { "X-CSRFToken": getCookie("csrftoken") }
        });
    });

    // 获取Cookie值
    function getCookie(name) {
        var arr1,reg1 = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if(arr1 = document.cookie.match(reg1)){
            return unescape(arr1[2]);
        }
        return null;
    }

</script>
</body>
</html>